package com.mgq.design.create.factory;

/**
 * <b>功能：</b>工厂类<br>
 * <b>Copyright mgq</b>
 * <li>版本&nbsp;&nbsp;&nbsp;&nbsp;修改日期&nbsp;&nbsp;&nbsp;&nbsp;部　　门&nbsp;&nbsp;&nbsp;&nbsp;作　者&nbsp;&nbsp;&nbsp;&nbsp;变更内容</li><hr>
 * <li>v1.0&nbsp;&nbsp;&nbsp;&nbsp;20220317&nbsp;&nbsp;营业后台&nbsp;&nbsp;&nbsp;&nbsp;马广奇&nbsp;&nbsp;&nbsp;&nbsp;创建类</li>
 * <br><br>
 *
 * @author 马广奇
 * @version 2022-03-17 17:04
 */
public class ShapeFactory {
    /**
     * <b>功能描述：</b>根据名称返回形状<br>
     * <b>修订记录：</b><br>
     * <li>20220317&nbsp;&nbsp;|&nbsp;&nbsp;马广奇&nbsp;&nbsp;|&nbsp;&nbsp;创建方法</li><br><br>
     *
     * @param shapeType 类型名
     * @return Shape
     */

    public static Shape getShape(String shapeType) {
        if (shapeType == null) {
            return null;
        } else if (shapeType.equalsIgnoreCase("RECTANGLE")) {
            return new Rectangle();
        } else if (shapeType.equalsIgnoreCase("Circle")) {
            return new Circle();
        } else if (shapeType.equalsIgnoreCase("Square")) {
            return new Square();
        } else {
            return null;
        }

    }

    /**
     * <b>功能描述：</b>根据类型返回形状<br>
     * <b>修订记录：</b><br>
     * <li>20220317&nbsp;&nbsp;|&nbsp;&nbsp;马广奇&nbsp;&nbsp;|&nbsp;&nbsp;创建方法</li><br><br>
     *
     * @param clazz  clazz
     *@return Shape
     */

    public static Shape getShape(Class<?> clazz) {
        String name = clazz.getName();
        return getShape(name.substring(name.lastIndexOf(".")+1));
    }
}
